package com.yaoxun.bored.controller.main;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.code.kaptcha.Producer;
import com.yaoxun.bored.common.Constant;

/**
 * 验证码控制器
 * 
 * @author Loren
 * @createTime 2018年1月31日 下午5:05:53
 */
@Controller
public class CaptchaController {

	@Inject
	private Producer producer;

	@RequestMapping(value = "/vcode")
	public void vcode(HttpServletResponse response, HttpSession session) throws IOException {
		String vcode = producer.createText();
		session.setAttribute(Constant.VCODE_SESSION_NAME, vcode);
		BufferedImage bufferedImage = producer.createImage(vcode);
		ImageIO.write(bufferedImage, "jpg", response.getOutputStream());
	}

}
